package com.zxw.flow.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zxw.common.core.base.res.BasePageRes;
import com.zxw.common.core.base.res.BaseRes;
import com.zxw.flow.api.FlowTypeApi;
import com.zxw.flow.domain.dto.FlowTypeDTO;
import com.zxw.flow.domain.entity.FlowType;
import com.zxw.flow.domain.vo.FlowTypePageVO;
import com.zxw.flow.domain.vo.FlowTypeVO;
import com.zxw.flow.service.FlowTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-07-04
 */
@Api(tags = "流程类型模块")
@RestController
@RequestMapping("/flow-type")
@RequiredArgsConstructor
public class FlowTypeController implements FlowTypeApi {

    private final FlowTypeService flowTypeService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "flowTypeName",value = "流程名称",required = true),
            @ApiImplicitParam(name = "serviceType",value = "流程类型：0-订单 1-采购 2-生产 3-报销 4-请假",required = true),
            @ApiImplicitParam(name = "pageNum",value = "页码",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页记录数",required = true),
            @ApiImplicitParam(name = "companyId",value = "公司id",required = true)
    })
    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("获取用户类型分页数据")
    @GetMapping("/flow-type-list")
    public BasePageRes<FlowType> page(FlowTypePageVO flowTypePageVO) {
        IPage<FlowType> page = flowTypeService.getPage(flowTypePageVO);
        return BasePageRes.success(page);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("根据id获取流程类型数据")
    @GetMapping("/{flowTypeId}")
    public BaseRes<FlowType> findFlowTypeById(@PathVariable("flowTypeId") Long flowTypeId) {
        FlowType f = flowTypeService.getFlowTypeById(flowTypeId);
        return BaseRes.ok(f);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("添加流程类型数据")
    @PostMapping("/insert")
    public BaseRes<FlowTypeVO> insertFlowType(@RequestBody FlowTypeVO flowTypeVO) {
        FlowTypeVO f = flowTypeService.add(flowTypeVO);
        return BaseRes.ok(f);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("更新流程类型数据")
    @PutMapping("/update/{flowTypeId}")
    public BaseRes updateFlowType(@PathVariable("flowTypeId") Long flowTypeId, @RequestBody FlowTypeVO flowTypeVO) {
        flowTypeService.updateBase(flowTypeVO);
        return BaseRes.okUpdate();
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("删除流程类型数据")
    @DeleteMapping("/{flowTypeIds}")
    public BaseRes deleteFlowType(@PathVariable("flowTypeIds") String flowTypeIds) {
        flowTypeService.delete(flowTypeIds);
        return BaseRes.okDelete();
    }
}
